unit mainform;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, IfxLocator, IfxSQL, IfxConnection,
  IfxVisualMonitor, IfxFileMonitor, IfxMonitor, LXDataSetImpl, LXUpdateSQL,
  IfxUpdateSQL, IfxDataSet, IfxQuery, IfxCustomDataSet, IfxTable,
  IfxFieldTypes, LXSQLProcessor, IfxSQLProcessor, IfxValues;

type
  TForm1 = class(TForm)
    Button1: TButton;
    IfxConnection1: TIfxConnection;
    Memo1: TMemo;
    Button2: TButton;
    IfxConnection2: TIfxConnection;
    IfxSQLProcessor1: TIfxSQLProcessor;
    IfxFieldTypes1: TIfxFieldTypes;
    IfxTable1: TIfxTable;
    IfxQuery1: TIfxQuery;
    IfxDataSet1: TIfxDataSet;
    IfxUpdateSQL1: TIfxUpdateSQL;
    IfxSQL1: TIfxSQL;
    IfxCompositMonitor1: TIfxCompositMonitor;
    IfxFileMonitor1: TIfxFileMonitor;
    IfxVisualMonitor1: TIfxVisualMonitor;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses IfxConvert, IfxLob;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  Lob: IIfxLob;
  LobStrategy: TIfxLobBufferStrategy;
  Params: TIfxParams;
  FileStream: TFileStream;
  LobStream: TStream;
begin
  Lob := TIfxLob.Create(IfxConnection1);

  FileStream := TFileStream.Create('L:\Products\IDAC\Version\source\IfxConsts.pas', fmOpenRead);
  LobStream := TIfxLobStream.Create(Lob);
  try
    LobStream.CopyFrom(FileStream, 0);
  finally
    FileStream.Free;
    LobStream.Free;
  end;

  //Lob.LoadFromFile('L:\Products\IDAC\Version\source\IfxFieldTypes.pas');

  with Lob.ObtainStatus do
  begin
    Memo1.Lines.Add(IntToStr(ReferenceCount));
    Memo1.Lines.Add(Int8ToString(Size));
    Memo1.Lines.Add(Int8ToString(StorageParams.BytesEstimated));
    Memo1.Lines.Add(Int8ToString(StorageParams.MaximumBytes));
    Memo1.Lines.Add(StorageParams.SBSpace);
  end;

  LobStrategy := TIfxLobBufferStrategy.Create(IfxConnection1);;
  Params := TIfxParams.Create;
  try
    Params.LobBufferStrategy := LobStrategy;
    Params.Reset(2);

    Params[0].AsClob := Lob;
    Params[1].AsBlob := Lob;
    IfxConnection1.Execute('update regress set c_clob = ?, c_blob = ?', Params);
  finally
    Params.Free;
    LobStrategy.Free;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  FileStream: TFileStream;
  LobStream: TStream;
  Lob: IIfxLob;
begin
  with TIfxSQL.Create(nil) do
    try
      Connection := IfxConnection1;
      SQL.Text := 'select first 1 c_clob, c_blob from regress';
      Open;
      Lob := Fields[1].AsBlob;
    finally
      Free;
    end;

  Lob.Open(LO_RDWR);
  FileStream := TFileStream.Create('d:\blob.tmp', fmCreate);
  LobStream := TIfxLobStream.Create(Lob);
  try
    FileStream.CopyFrom(LobStream, 0);
  finally
    FileStream.Free;
    LobStream.Free;
  end;
  Lob.SaveToFile('d:\blob.tmp');
  with Lob.ObtainStatus do
  begin
    Memo1.Lines.Add(IntToStr(ReferenceCount));
    Memo1.Lines.Add(Int8ToString(Size));
    Memo1.Lines.Add(Int8ToString(StorageParams.BytesEstimated));
    Memo1.Lines.Add(Int8ToString(StorageParams.MaximumBytes));
    Memo1.Lines.Add(StorageParams.SBSpace);
  end;
end;

end.
